Each problem must be submitted as its own .cpp file. Grading for each problem is as follows:
- Write a complete C++ program that does the following:
- Prompts the user for:
- their name
- age (in years)
- height in inches
- Says "hello" to the user (using their name) and tells them:
- their age in days
- their height in feet and inches
Sample run of program:
What is your name? Cathy
What is your height in inches? 66
What is your age? 24
Hello, Cathy.
Your age in days is 8760.
Your height in feet and inches is 5 feet 6 inches.
- Write a complete C++ program that does the following:
- Prompts the user for two integers.
- Tells the user whether the second integer evenly divides into the first.
- Computes the quotient (the number of times the first number divides into the second) and remainder when the first integer is divided by the second.
- Computes the precise result (i.e., result with any fractional part) when the first integer is divided by the second.
Sample run of program:
Enter two integers: 34 27
When 34 is divided by 27, the quotient is 1 and the remainder is 7
The precise result is 1.25926
- Write a complete C++ program that does the following:
- Prompts the user to enter their temperature (in Fahrenheit).
- Converts the temperature to Celsius (cTemp) using the following formula, where fTemp is the temperature in Fahrenheit:
- cTemp = (fTemp − 32) * 5/9
- Prints the temperature in Celsius to the monitor.
- If the Celsius temperature is greater than 37, print "You have a fever. Drink lots of liquids and go to bed." to the monitor.
- Otherwise, print "You don't have a fever. Go study." to the monitor.
Sample run of program:
Enter your temperature in Fahrenheit: 98
Your temperature in Celsius is 36.6667
You don't have a fever. Go study.
Another sample run of program:
Enter your temperature in Fahrenheit: 100
Your temperature in Celsius is 37.7778
You have a fever. Drink lots of liquids and go to bed.
- Write a complete C++ program that does the following:
- Prompts the user for a two- or three-digit integer.
- If the input does not have the required amount of digits, tell the user "You are not playing nicely." and end the program. (You can use a second "return 0" before the program sign-off to end the program earlier.)
- If it is a two-digit number, print the leftmost digit (i.e., tens digit) to the monitor
- If it is a three-digit number, print the middle digit to the monitor.
Sample run of program:
Enter a two- or three-digit number: 7894
You are not playing nicely.
Another sample run of program:
Enter a two- or three-digit number: 23
The leftmost digit is 2
Another sample run of program:
Enter a two- or three-digit number: 489
The middle digit is 8
- Complete both parts of this problem:
- Convert each of the following mathematical formulas to C++ expressions:
- 3x
- 3x+y
- (x+y)/7
- (3x+y)/(z+2)
- Write a complete C++ program that does the following:
- Prompts the user for three integers x, y, z.
- Computes each of the four expressions above using the values for x, y, z provided by the user.
- Prints each result to the monitor.
- You only need to submit the completed C++ program. You do not need to separately submit part a.
Sample run of program:
Enter three integers: 2 43 17
3 * 2 = 6
3 * 2 + 43 = 49
(2 + 43) / 7 = 6.42857
(3 * 2 + 43) / (17 + 2) = 2.57895
Another sample run of program:
Enter three integers: 87 56 24
3 * 87 = 261
3 * 87 + 56 = 317
(87 + 56) / 7 = 20.4286
(3 * 87 + 56) / (24 + 2) = 12.1923
- Write a complete C++ program that prompts the user for the time (two integers; hour and minute) and whether it is AM or PM.
- If the user enters 9:00 AM, tell them it is time for breakfast.
- If the user enters 5:30 PM, tell them it is time for dinner.
- If the user enters a time after 8:00 PM, tell them it is time for an evening snack.
- If none of the above times are entered, tell the user it is not time to eat.
Sample run of program:
Enter the current time.
Hour: 7
Minute: 43
AM or PM? AM
It's not time to eat.
Another sample run of program:
Enter the current time.
Hour: 5
Minute: 30
AM or PM? PM
Time for dinner!
Another sample run of program:
Enter the current time.
Hour: 8
Minute: 37
AM or PM? PM
Time for evening snack!
- Write a complete C++ program that does the following:
- Prompt the user for their birthdate, where the user enters three integers: month, day, year.
- If the date falls between 9/16 and 3/15 the program should print "You were born in fall or winter" to the monitor.
- If the date falls between 3/16 and 9/15 the program should print "You were born in spring or summer" to the monitor.
- Test to see if the year is a leap year. A leap year is
- evenly divisible by 4 but not evenly divisible by 100, or
- evenly divisible by 400
- If the year is a leap year, the program should print "You were born in a leap year."
- Otherwise the program should print "You were not born in a leap year."
Sample run of program:
Enter your birth month: 3
Enter your birth day: 17
Enter your birth year: 2004
You were born in spring or summer.
You were born in a leap year.
Another sample run of program:
Enter your birth month: 10
Enter your birth day: 1
Enter your birth year: 2003
You were born in fall or winter.
You were not born in a leap year.